package net.hn.hnms.biz.meeting.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import net.hn.hnms.biz.meeting.request.ScheduleMiningReq;
import net.hn.hnms.biz.meeting.service.ScheduleMiningService;
import net.hn.hnms.biz.meeting.vo.ScheduleMiningVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(value = "日程", tags = {"日程管理"})
@RestController
@RequestMapping("/Schedule/info")
@RequiredArgsConstructor
public class ScheduleMiningController extends BaseController {

    @Autowired
    private ScheduleMiningService scheduleMiningService;



    @ApiOperation("日程列表")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<ScheduleMiningVo>> page(ScheduleMiningReq meetingRoomReq, PageQuery pageQuery) {
        return R.ok(scheduleMiningService.selectPageList(meetingRoomReq, pageQuery));
    }

    @ApiOperation("删除日程")
    @SaCheckPermission("schedule:management:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @PostMapping("delete")
    @Log(title = "删除日程", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        scheduleMiningService.updateDeleteByIds(idList);
        return R.ok();
    }

    @ApiOperation("新增日程")
    @SaCheckPermission("schedule:management:add")
    @PostMapping("/add")
    @Log(title = "新增日程", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody ScheduleMiningReq meetingRoomReq) {
        return toAjax(scheduleMiningService.insert(meetingRoomReq));
    }


    @ApiOperation("更新日程")
    @SaCheckPermission("schedule:management:update")
    @PostMapping("/update")
    @Log(title = "更新日程", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody ScheduleMiningReq meetingRoomReq) {
        scheduleMiningService.updateById(meetingRoomReq);
        return R.ok();
    }

//    @ApiOperation("会议室预约列表")
//    @GetMapping("/reservation")
//    @AutoSetMineCode
//    public R<List<ScheduleMiningVo>> reserve(@RequestParam(value = "dateTime",required = false)
//                                          @DateTimeFormat(pattern = "yyyy-MM-dd")
//                                          Date dateTime, @ApiParam(value = "煤矿编码") String mineCode, @ApiParam(value = "公司编码") String companyCode) {
//        return R.ok(scheduleMiningService.selectReservePageList(dateTime,mineCode,companyCode ));
//    }



    @ApiOperation("修改日程状态")
    @SaCheckPermission("schedule:management:change")
    @PutMapping("/change")
    @Log(title = "修改日程状态", businessType = BusinessType.UPDATE)
    public R<Void> change(@RequestParam("scheduleId") String scheduleId, @RequestParam("state") Integer state) {
        scheduleMiningService.changeStatus(scheduleId, state);;
        return R.ok();
    }
    @ApiOperation("获取日程列表")
//    @SaCheckPermission("plan:mining:list")
    @GetMapping("/list")
    public R<List<ScheduleMiningVo>> list(ScheduleMiningReq planMining) {
        return R.ok(scheduleMiningService.selectList(planMining));
    }


    @ApiOperation("获取日程数据")
//    @SaCheckPermission("plan:mining:list")
    @GetMapping("/data")
    public R<List<ScheduleMiningVo>> data(ScheduleMiningReq planMining) {
        return R.ok(scheduleMiningService.selectListData(planMining));
    }
}
